/**
 * CORBA SERVER PROVIDING ONE REMOTE SERVICE TO THE RMI SERVER
 * USE THE COMMAND INTERFACE TO PRINT THE TRACE OF ACTIVITIES OF THIS SERVER
 */
package corbaServer;

import corbaServer.corba.*;
import org.omg.CORBA.ORB;
import org.omg.CosNaming.*;
import org.omg.PortableServer.*;


public class CorbaRaceServer{

	public static void main(String[] args) {
		try{
			String[] orb_args= {"-ORBInitialHost", args[0], "ORBInitialPort", args [1]};
			ORB orb= ORB.init(orb_args, null);
			org.omg.CORBA.Object reference= orb.resolve_initial_references("RootPOA");
			POA poa= POAHelper.narrow(reference);
			poa.the_POAManager().activate();
			CServer cserver= new CServer();
			cserver.setName(args[2]);
			org.omg.CORBA.Object ref= poa.servant_to_reference(cserver);
			ICorbaServer racesRef= ICorbaServerHelper.narrow(ref);
			org.omg.CORBA.Object objRef= orb.resolve_initial_references("NameService");
			NamingContextExt ncRef= NamingContextExtHelper.narrow(objRef);
			String name= args[2];
			NameComponent[] path= ncRef.to_name(name);
			
			ncRef.rebind(path, racesRef);
			
			System.out.println(name + " corba server waiting...");
			
			orb.run();
			
			
		}catch(Exception e){
			System.out.println("Error al crear ORB");
		}
	}

	
	
}
